//
//  OnLinePeopleCell.m
//  YouinRTCDemo
//
//  Created by 潘欣 on 2023/6/23.
//

#import "OnLinePeopleCell.h"

@interface OnLinePeopleCell ()
@property (nonatomic,strong)UIImageView *img;
@property (nonatomic,strong)UILabel *name;
@end

@implementation OnLinePeopleCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if([super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        
        
        [self.message mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self).offset(20);
            make.centerY.mas_equalTo(self);
            make.width.height.offset(10);
        }];
        
        [self.img mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.message.mas_right).offset(10);
            make.width.height.offset(40);
            make.centerY.mas_equalTo(self);
        }];
        
        [self.imgCover mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.height.mas_equalTo(self.img);
            make.centerX.centerY.mas_equalTo(self.img);
        }];
        
        [self.name mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.img.mas_right).offset(10);
            make.width.offset(200);
            make.centerY.mas_equalTo(self);
        }];
        
       
        
        [self.privateChat mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self).offset(-20);
            make.width.offset(60);
            make.height.offset(25);
            make.centerY.mas_equalTo(self);
        }];
    }
    return self;
}

- (void)setModel:(OnlineModel *)model
{
    _model = model;
    [self.img sd_setImageWithURL:[NSURL URLWithString:model.headImageUrl]];
    self.name.text = model.nickname;
    self.imgCover.hidden = NO;
    if (model.online) {
        self.imgCover.hidden = YES;
    }

}
- (UIImageView *)img
{
    if(!_img){
        _img = [[UIImageView alloc] init];
        _img.layer.cornerRadius = 20;
        _img.clipsToBounds = YES;
        _img.backgroundColor = [UIColor lightGrayColor];
        [self addSubview:_img];
    }
    
    return _img;
}


- (UILabel *)imgCover
{
    if(!_imgCover){
        _imgCover = [UILabel new];
        _imgCover.layer.cornerRadius = 20;
        _imgCover.layer.masksToBounds = YES;
        _imgCover.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.5];
        _imgCover.text = @"离线";
        _imgCover.font = [UIFont systemFontOfSize:12];
        _imgCover.textAlignment = 1;
        _imgCover.textColor = [UIColor whiteColor];
        [self addSubview:_imgCover];
    }
    return _imgCover;
}

- (UILabel *)name
{
    if (!_name) {
        _name = [[UILabel alloc] init];
        _name.text = @"欧式座椅";
        _name.textColor = [UIColor blackColor];
        _name.font = [UIFont systemFontOfSize:13];
        [self addSubview:_name];
    }
    return _name;
}

- (UILabel *)message
{
    if(!_message){
        _message = [[UILabel alloc] init];
        _message.layer.cornerRadius = 5;
        _message.clipsToBounds = YES;
        _message.backgroundColor = [UIColor redColor];
        _message.hidden = YES;
        [self addSubview:_message];
    }
    return _message;
}
- (UIButton *)privateChat
{
    if(!_privateChat){
        _privateChat = [UIButton buttonWithType:UIButtonTypeCustom];
        [_privateChat setTitle:@"私聊" forState:UIControlStateNormal];
        [_privateChat setTitleColor:rgba(25, 148, 255, 1) forState:UIControlStateNormal];
        _privateChat.layer.cornerRadius = 5;
        _privateChat.layer.borderWidth = 1;
        _privateChat.titleLabel.font = [UIFont systemFontOfSize:14];
        _privateChat.layer.borderColor = rgba(25, 148, 255, 1).CGColor;
        [self.contentView addSubview:_privateChat];
    }
    return _privateChat;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
